<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="utf-8">
    <title>申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-container">

    <div class="layui-form layui-input-inline layuimini-form" th:object="${detail}">
        <input type="hidden" th:field="*{department}">
        <input type="hidden" th:field="*{p_title}">
        <input type="hidden" th:field="*{name}">
<!--        <input type="hidden" name="name" id="roleName" value="">-->
        <div class="layui-form-item layui-form-text" style="width: 550px;">
            <textarea name="note" class="layui-textarea" placeholder="填写个人相关信息更容易通过哦！"></textarea>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">提交申请</button>
                <button class="layui-btn layui-btn-primary" lay-submit lay-filter="cancelBtn">取消申请</button>
            </div>
        </div>
    </div>
</div>
<script src="layui/layui.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/jquery-3.6.3.js"></script>
<script>
    //当页面一加载时就向后台发送post请求,获取当前用户的姓名


    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // $(function(){
        //     $.post("../getusername",function(obj){
        //         console.log("当前用户姓名已查出。");
        //         $("#roleName").val(obj.name);
        //     },"json")
        // });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var userData = data.field;
            // var obj1 = parent.document.getElementById("apply");
            // obj1.className = "layui-btn layui-btn-xs layui-btn-disabled data-count-delete";
            // obj1.setAttribute('lay-event','')
            $.ajax({
                type: 'POST',
                url: window.location.protocol + '//' + window.location.host + '/applyGw',
                dataType: 'html',
                data: JSON.stringify(userData),
                contentType: 'application/json',
                success: function (data) {
                    // 关闭弹出层
                    if (data==1){
                        parent.layer.msg("提交成功");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }else if(data == 0){
                        layer.msg("服务器异常，请稍后重试！");
                    }else if (data == 2){
                        layer.msg("请勿重复申请！");
                    }else {
                        layer.msg("人数已满，请申请其他岗位！");
                    }

                },
                error: function () {
                    //console.log(data);
                    layer.close(registerLoadIndex);
                    layer.alert("请求超时！")
                }
            });
            return false;
        });

        form.on('submit(cancelBtn)', function () {
            $('.layui-textarea').val('');
            parent.layer.closeAll();
           return false;
        });

    });
</script>
</body>
</html>